package com.kevin.data.batch.component;

import com.kevin.data.batch.configuration.BizJobListener;
import jakarta.annotation.Resource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;

/**
 * 默认处理
 */
@Component
public class SimpleBatchComponent {

    @Resource
    private JobRepository jobRepository;

    @Resource
    private BizJobListener jobListener;

    @Resource
    private PlatformTransactionManager transactionManager;

    @Bean("simpleJob")
    public Job simpleJob() {
        Step step = new StepBuilder("simpleStep", jobRepository).tasklet((contribution, chunkContext) -> {
            System.err.println("simpleStep test......");
            return RepeatStatus.FINISHED;
        }, transactionManager).allowStartIfComplete(true).build();
        return new JobBuilder("simpleJob", jobRepository).start(step).listener(jobListener).build();
    }

}
